package com.gticket.orderservice.util;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author: 伴你时光尽头
 * @Date: 2019/11/5 12:07
 */
public class RabbitUtils {

    /**
     * 返回一个RabbitMQ的连接
     *
     * @return
     */
    public static Connection getConnection() {
        ConnectionFactory factory = new ConnectionFactory();//创建连接工厂对象
        factory.setVirtualHost("/");//指定RabbitMQ服务器的虚拟主机
        factory.setHost("101.132.131.239");//设置主机名/主机ip
        factory.setPort(5672);//指定端口号
        factory.setUsername("guest");//设置连接用户名
        factory.setPassword("guest");//指定连接用户密码
        Connection connection = null;
        try {
            connection = factory.newConnection();//创建连接
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }

        return connection;
    }
}
